<template>
  <div class="checked-box" @click="checkClick">
    <div class="flex">
      <div
        class="checked-item flex"
        :class="[
          {
            'checked-rect': type == 'rect',
            'checked-circle': type == 'circle',
          },
        ]"
      >
        <div v-show="checked" class="select-active select-icon iconfont flex">
          &#xe630;
        </div>
        <div v-show="!checked" class="select-icon select-border"></div>
      </div>

      <div class="check-label" v-if="label">{{ label }}</div>
      <div class="check-label">
        <slot></slot>
      </div>
    </div>
  </div>
</template>
<script setup>
import { computed } from "vue";
const props = defineProps({
  modelValue: {
    default: false,
  },
  label: {
    default: "",
  },
  disable: {
    default: false,
  },
  readonly: {
    default: false,
  },
  //rect矩形,circle圆形
  type: {
    default: "rect",
  },
});

let checked = computed({
  get: () => {
    return props.modelValue;
  },
  set: (newVal) => {
    emits("update:modelValue", newVal);
  },
});

const emits = defineEmits(["update:modelValue", "checkClick"]);
function checkClick() {
  emits("checkClick", props.modelValue);
  if (props.disable || props.readonly) {
    return;
  }
  checked.value = !checked.value;
}
</script>
<style lang="scss" scoped>
.checked-box {
  display: inline-block;
  line-height: 36rpx;
  margin: 10rpx;
  .checked-item {
    width: 36rpx;
    height: 36rpx;
    color: #666;
    font-size: 0;
    margin-right: 10rpx;
    border: 1px solid #dcdfe6;
    overflow: hidden;
    .select-icon {
      width: 100%;
      height: 100%;
      box-sizing: border-box;
      font-size: 34rpx;
      background-color: #fff;
    }
    .select-active {
      color: $theme-color;
    }
    .select-border {
      background-color: #fff;
      border-radius: 6rpx;
      overflow: hidden;
    }
  }
  .checked-rect {
    border-radius: 8rpx;
  }
  .checked-circle {
    border-radius: 50%;
  }
  .check-label {
    font-size: 28rpx;
  }
}
</style>
